/**
 * @author LKQ
 * @date 2022/2/27 14:41
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.maxScore("00");
    }
    public int maxScore(String s) {
        char[] chars = s.toCharArray();
        // 统计0位置有左边有几个零，右边几个1
        int max  = 0,  cnt0 = 0, cnt1 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i == 0 && chars[i] == '0') {
                cnt0++;
            }
            if (i > 0 && chars[i] == '1') {
                cnt1++;
            }
        }
        max = cnt0 + cnt1;
        for (int i = 1; i < s.length() - 1; i++) {
            if (chars[i] == '0') {
                cnt0++;
            }else if (chars[i] == '1') {
                cnt1--;
            }
            max = Math.max( max , cnt0 + cnt1);
        }
        return max;
    }
}
